import request from "@/utils/request";
import {
  SysNotifyEditForm,
  WorkerNotifyEditForm,
  QueryParams,
} from "@/api/notify/types";

//获取系统通知列表
export function getSysNotifysByPage(data: QueryParams) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/sysnotify/page";
      break;
    case "Corp":
      url = "/api/v1/corp/sysnotify/page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/sysnotify/page";
      break;
    case "Commander":
      url = "/api/v1/commander/sysnotify/page";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/sysnotify/page";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

//获取系统通知详情
export function getSysNotifyById(id?: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/sysnotify/form/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/sysnotify/form/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/sysnotify/form/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/sysnotify/form/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/sysnotify/form/" + id;
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

//创建系统通知
export function addSysNotify(data: SysNotifyEditForm) {
  return request({
    url: "/api/v1/sysuser/sysnotify/add",
    method: "post",
    data: data,
  });
}

//编辑系统通知
export function editSysNotify(data: SysNotifyEditForm) {
  return request({
    url: "/api/v1/sysuser/sysnotify/update",
    method: "put",
    data: data,
  });
}

//删除系统通知
export function delSysNotify(id: string) {
  return request({
    url: "/api/v1/sysuser/sysnotify/del/" + id,
    method: "delete",
  });
}

//获取工人通知列表
export function getWorkerNotifysByPage(data: QueryParams) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/workernotify/page";
      break;
    case "Corp":
      url = "/api/v1/corp/workernotify/page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/workernotify/page";
      break;
    case "Commander":
      url = "/api/v1/commander/workernotify/page";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/workernotify/page";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

//获取工人通知详情
export function getWorkerNotifyById(id?: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/workernotify/form/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/workernotify/form/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/workernotify/form/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/workernotify/form/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/workernotify/form/" + id;
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

//创建工人通知
export function addWorkerNotify(data: WorkerNotifyEditForm) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/workernotify/add";
      break;
    case "Corp":
      url = "/api/v1/corp/workernotify/add";
      break;
    case "Constructor":
      url = "/api/v1/constructor/workernotify/add";
      break;
    case "Commander":
      url = "/api/v1/commander/workernotify/add";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/workernotify/add";
      break;
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

//编辑工人通知
export function editWorkerNotify(data: WorkerNotifyEditForm) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/workernotify/update";
      break;
    case "Corp":
      url = "/api/v1/corp/workernotify/update";
      break;
    case "Constructor":
      url = "/api/v1/constructor/workernotify/update";
      break;
    case "Commander":
      url = "/api/v1/commander/workernotify/update";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/workernotify/update";
      break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}
//删除工人通知
export function delWorkerNotify(id: string) {
  return request({
    url: "/api/v1/manager/workernotify/del/" + id,
    method: "delete",
  });
}
//导出工人通知
export function exportWorkerNotify(query: QueryParams) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/workernotify/export";
      break;
    case "Corp":
      url = "/api/v1/corp/workernotify/export";
      break;
    case "Constructor":
      url = "/api/v1/constructor/workernotify/export";
      break;
    case "Commander":
      url = "/api/v1/commander/workernotify/export";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/workernotify/export/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
    responseType: "arraybuffer",
  });
}
